package admin.user;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.common.CommonUtil;
import com.common.Dateutil;
import com.common.ResultData;
import com.filter.BaseController;
import com.intercepter.AuthPassport;

import beans.subject.ChapterModelSearch;
import beans.subject.subchapterBean;
import beans.sys.UserBean;
import beans.user.UserSearch;
import beans.user.user;
import service.user.WXUserServiceImpl;
@Controller
@RequestMapping("/wxadminuser")
public class WXAdminUserController  extends BaseController{
	@Resource
	private WXUserServiceImpl<user> wXUserServiceImpl;

	@AuthPassport(actionName="index",controllerName="wxadminuser")
	@RequestMapping("/index")
	public String Index(){
		return "admin/wxuser/index";
	}
	
	@RequestMapping("/GetData")
	@ResponseBody
	@AuthPassport(actionName="index",controllerName="wxadminuser")
	public void DataGrid(UserSearch model){
		ResultData<List<user>> rd = new ResultData<>();
		try{
			rd.setPage(model.getPage());

			if(!CommonUtil.isNullObject(model.getEndtime())){
				model.setEndtime(Dateutil.nextDate(model.getEndtime()));
			}

			List<user> m = wXUserServiceImpl.queryByList(model);
			
			rd.setRows(m);
			rd.setRecords(model.getPager().getRowCount());
			rd.setTotal(model.getPager().getPageCount());
		}
		catch(Exception e){
			e.printStackTrace();
		}
		responseJson(rd);
	}
	
	@AuthPassport(actionName="index",controllerName="wxadminuser")
	@RequestMapping("/delete")
	@ResponseBody
	public void Delete() {
		ResultData<String> rd = new ResultData<>();
		String[] ids = getReq().getParameterValues("ids");
		try{
			wXUserServiceImpl.deletes(ids);
			rd.setType(1);
			rd.setMessage("删除成功");
		}
		catch(Exception e){
			e.printStackTrace();
			rd.setType(3);
			rd.setMessage("删除失败");
		}
		responseJson(rd);
	}
}
